import { getArticleList, getArticleDetail } from '../service/article.js';


export const getArticleListHandler = async (request, reply) => {
    const { pageNum, pageSize } = request.query;

    try {
        const data = await getArticleList(pageNum, pageSize);
        return reply.send({ code: 200, data, msg: 'success' });
    } catch (err) {
        request.log.error(err);
        return reply.status(500).send({ success: false, message: 'Server error' });
    }
};


export const getArticleDetailHandler = async (request, reply) => {
    const { id } = request.params;

    console.log(request.params, 'id');


    try {
        const data = await getArticleDetail(+id);
        return reply.send({ code: 200, data, msg: 'success' });
    } catch (err) {
        request.log.error(err);
        return reply.status(500).send({ success: false, message: 'Server error' });
    }
}